﻿#region License statement
// NJamb, a specification and delta-specification DSL
// Copyright (c) 2010-2011, Mark Knell
// Published under the MIT License; all other rights reserved
#endregion

#region using...
using System;
using System.Collections.Generic;
using System.Linq;
using NJamb.Parser.SpecificationBuilders.SubjectHas.Simple.Enumerable;
using NJamb.Parser.SubjectBuilders;
using NJamb.Specifications.Simple.Enumerable;
using NUnit.Framework;
using Stile.NUnit;
using Stile.Patterns.SelfDescribingPredicates;
#endregion

namespace NJamb.Tests.Parser.SpecificationBuilders.SubjectHas.Simple.Enumerable
{
    [TestFixture]
    public class EnumerableHasFixture : SampleFixture
    {
        private EnumerableHas<IEnumerable<int>, int> _testSubject;

        [Test]
        public void CountOf()
        {
            Assert.That(_sample.IntEnumerable.Any(), Is.False, "Precondition");
            // arrange
            const int count = -8;
            IEnumerableSpecification<IEnumerable<int>, int> enumerableSpecification = _testSubject.CountOf(count);

            // act
            IEvaluation evaluation = enumerableSpecification.Evaluate();

            // assert
            Assert.That(evaluation.Success, Is.False);
            Assert.That(evaluation.Reason,
                Is.EqualTo(
                    string.Format(
                        "expected _sample.IntEnumerable would have count of {0}" + Environment.NewLine + " but had count of 0.",
                        count)));
        }

        protected override void SetupComplete()
        {
            _testSubject =
                (EnumerableHas<IEnumerable<int>, int>) Specify.For(() => _sample).ThatTheSequence(x => x.IntEnumerable).Has;
        }
    }
}
